import request from '@/utils/request'
import { AxiosPromise } from 'axios'
import { IotDeviceVO, IotDeviceQuery, IotDeviceForm } from './types'

/**
 * 查询设备列表
 */
export const listDevice = (query: IotDeviceQuery): AxiosPromise<IotDeviceVO[]> => {
  return request({
    url: '/iot/device/list',
    method: 'get',
    params: query
  })
}

/**
 * 分页查询设备列表
 */
export const pageDevice = (query: IotDeviceQuery): AxiosPromise<any> => {
  return request({
    url: '/iot/device/page',
    method: 'get',
    params: query
  })
}

/**
 * 根据分组ID查询设备列表
 */
export const listDeviceByGroupId = (groupId: number): AxiosPromise<IotDeviceVO[]> => {
  return request({
    url: `/iot/device/group/${groupId}`,
    method: 'get'
  })
}

/**
 * 查询设备详细
 */
export const getDevice = (deviceId: number): AxiosPromise<IotDeviceVO> => {
  return request({
    url: `/iot/device/${deviceId}`,
    method: 'get'
  })
}

/**
 * 新增设备
 */
export const addDevice = (data: IotDeviceForm) => {
  return request({
    url: '/iot/device',
    method: 'post',
    data: data
  })
}

/**
 * 修改设备
 */
export const updateDevice = (data: IotDeviceForm) => {
  return request({
    url: '/iot/device',
    method: 'put',
    data: data
  })
}

/**
 * 删除设备
 */
export const delDevice = (deviceIds: number | Array<number>) => {
  return request({
    url: `/iot/device/${deviceIds}`,
    method: 'delete'
  })
} 